package com.itheima.controller;

import com.itheima.pojo.*;
import com.itheima.pojo.nursing.NursingLevel;
import com.itheima.pojo.nursing.NursingLevelParam;
import com.itheima.service.NursingLevelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

@RestController
@RequestMapping("/nursingLevel")
public class NursingLevelController {

    @Autowired
    private NursingLevelService nursingLevelService;

    @GetMapping
    public Result page(NursingLevelParam nursingLevelParam){
        return Result.success(nursingLevelService.page(nursingLevelParam));
    }

    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id){
        NursingLevel byId = nursingLevelService.getById(id);
        return Result.success(byId);
    }

    @PostMapping
    public Result add(@RequestBody NursingLevel nursingLevel){
        nursingLevel.setCreateTime(LocalDateTime.now());
        nursingLevel.setUpdateTime(LocalDateTime.now());
        nursingLevelService.save(nursingLevel);
        return Result.success();
    }

    @PutMapping
    public Result update(@RequestBody NursingLevel nursingLevel){
        nursingLevel.setUpdateTime(LocalDateTime.now());
        nursingLevelService.updateById(nursingLevel);
        return Result.success();
    }

    @DeleteMapping
    public Result delete(@RequestParam List<Integer> ids){
        nursingLevelService.removeByIds(ids);
        return Result.success();
    }

}
